<?php
namespace app\api\controller\v2;
use app\api\controller\Common;

class Order extends Common {
	var $modelDb;
	public function _initialize() {
		parent::_initialize();
		$this->modelDb = model("Order");
	}
	public function get_status() {
		$userid = $this->uinfo['id'];
		$info = model("Order")->where('ordersn', $this->postData['ordersn'])->find();
		if (empty($info)) {
			return $this->app_error('无此订单');
		}
		$status = $info['status'] == 1 ? 1 : 0;
		if ($status) {
			return $this->app_success(['status' => 1], '支付成功');
		} else {
			return $this->app_error(['status' => 0], '支付失败');
		}
	}

	public function get_ordermessage() {
		$userid = $this->uinfo['id'];
		$info = db("Order")->where('ordersn', $this->postData['ordersn'])->find();
		$info['amount'] = model("Member")->where('id', $info['userid'])->value('amount');
		if (!empty($info)) {
			return $this->app_success($info);
		}

	}
	public function exchange() {
		if (!$this->postData['addressid']) {
			return $this->app_error('请选择收货地址');
		}
		$this->postData['userid'] = $this->uinfo['userid'];
		$ids = model('OrderConvert')->save_datas($this->postData);
		if ($ids === false) {
			return $this->app_error(model('OrderConvert')->getError());
		}
		return $this->app_success();
	}
	public function receive_convert() {
		$ids = model('OrderConvert')->where('id', $this->postData['id'])->setField('status', 3);
		if ($ids === false) {
			return $this->app_error(model('OrderConvert')->getError());
		}
		return $this->app_success();
	}
}
